/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Login;

import Entity.Account;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author HOME
 */
@Stateless
public class LoginSessionBean implements LoginSessionBeanLocal {
    @PersistenceContext(unitName = "Group05_NationalLevelPaperPresentation-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    public Boolean checkLoginMethod(String Username, String Password) {
         boolean check = false;
        try {
                String ejbQl = "SELECT a FROM Account a WHERE a.username = :username AND a.password = :password";
               Query query = em.createQuery(ejbQl);
               query.setParameter("username", Username);
               query.setParameter("password", Password);
               List list = query.getResultList();
               if(list.size() > 0)
               {
                    check = true;
               }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return check;
    }

    public Account findAccountByPrimakey(String Username) {
       try {
            Account objAccount = em.find(Account.class, Username);
            return objAccount;
        } catch (Exception e) {
            e.printStackTrace();
        }
         return null;
    }


    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
